//
//  BrainStormFromHeadView.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/29.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "BrainStormFromHeadView.h"

@interface BrainStormFromHeadView ()<SDCycleScrollViewDelegate,PYSearchViewControllerDataSource>
{
    SDCycleScrollView *_sdView;
}
@property(nonatomic, strong) PYSearchViewController *searchViewController;//搜索
@property(nonatomic, strong) UIScrollView * demoContainerView;//滚动视图
@property (nonatomic,strong) NSMutableArray *imageArr;
//搜索条按钮
@property(nonatomic, strong) UIButton * searchButton;

@end

@implementation BrainStormFromHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self showBrainStormHeadView];
    }
    return self;
}

- (void)showBrainStormHeadView
{
    //创建滚动视图
    _demoContainerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(157))];
    //滚动视图的位置
    _demoContainerView.contentSize = CGSizeMake(UIScreenWidth,kHeightScale(157));
    
    self.imageArr = [NSMutableArray array];
    NSArray*arr=@[@"banner",@"ditu",@"banner"];
    //本地图片显示轮播图
    _sdView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(157)) delegate:self placeholderImage:[UIImage imageNamed:@""]];
    _sdView.imageURLStringsGroup = [NSArray arrayWithArray:arr];
    _sdView.contentMode = UIViewContentModeScaleAspectFit;
    //轮播图页数设置----小点
    _sdView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    //轮播图时间间隔
    _sdView.autoScrollTimeInterval = 2.0;
    [_demoContainerView addSubview:_sdView];
    _sdView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //添加到主视图中
    [self addSubview:_demoContainerView];
    
    _navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(64))];
    _navImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(64))];
    _navImage.userInteractionEnabled = YES;
    
    UIButton * news = [[UIButton alloc] initWithFrame:CGRectMake(kWidthScale(339), kHeightScale(25), kWidthScale(20), kHeightScale(20))];//
    [news setImage:[UIImage imageNamed:@"xiaoxi"] forState:UIControlStateNormal];
    [news addTarget:self action:@selector(tiaozhuangnews) forControlEvents:UIControlEventTouchUpInside];
    
    [_navImage addSubview:news];
    
    //    搜索条按钮
    _searchButton=[[UIButton alloc] initWithFrame:CGRectMake(kWidthScale(15), kHeightScale(20), UIScreenWidth - kWidthScale(60), kHeightScale(32))];//
    [_searchButton addTarget:self action:@selector(brainStormShearchHome) forControlEvents:UIControlEventTouchUpInside];
    [_searchButton setImage:[UIImage imageNamed:@"sousuo-2.jpg"] forState:(UIControlStateNormal)];
    [_searchButton setTitle:@" | 搜索" forState:UIControlStateNormal];
    _searchButton.titleLabel.font = [UIFont systemFontOfSize:kWidthScale(15)];
    _searchButton.layer.cornerRadius = kWidthScale(12);
    _searchButton.layer.masksToBounds = YES;
    _searchButton.backgroundColor = [UIColor blackColor];
    _searchButton.alpha = 0.4;
    _searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
    _searchButton.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
    _searchButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    [_navImage addSubview:_searchButton];
    
    [_navigationView addSubview:_navImage];
    
    [_demoContainerView addSubview:_navigationView];
    
    //创建shearch搜索内容，在搜索条内展示出来的比较热门的
    NSArray*hostArr=@[@"索大大",@"王奎卿",@"杨凌云",@"牛文勤",@"垒哥",@"刘总",@"任总"];
    //创建Shearch视图显示
    _searchViewController=[PYSearchViewController searchViewControllerWithHotSearches:hostArr searchBarPlaceholder:@"天创网络" didSearchBlock:^(PYSearchViewController * searchViewController,UISearchBar * searchBar,NSString * searchText){
        //自动完成搜索时调用此块
        //如：推送到视图控制器
        if (self.searchPopBlock) {
            self.searchPopBlock(searchViewController);
        }
    }];
    
    //设置代理r
    _searchViewController.dataSource=self;
    //设置searchResultShowMode
    _searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
    // 2.设置searchResultController
    _searchViewController.searchResultController = [[UIViewController alloc ] init ];
    //设置hotSearchStyle
    _searchViewController.hotSearchStyle = PYHotSearchStyleColorfulTag;
    // Set searchHistoryStyle
    _searchViewController.searchHistoryStyle = PYSearchHistoryStyleBorderTag;
    //设置searchHistoriesCount
    _searchViewController.searchHistoriesCount = 6 ;
    // Set searchResultShowMode
    _searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
    // Set searchSuggestionHidden
    _searchViewController.searchSuggestionHidden = YES ;
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"首页banner点击了第%ld个",index);
}

- (void)didClickCancel:(PYSearchViewController *)searchViewController {
    if (self.searchPopBlock) {
        self.searchPopBlock(searchViewController);
    }
}

- (void)brainStormShearchHome
{
    if (self.searchPushBlock)
    {
        self.searchPushBlock(_searchViewController);
    }
}

- (void)tiaozhuangnews
{
    if (self.newspushBlock) {
        self.newspushBlock(YES);
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
